package controller

import (
	"context"
	v1 "tFilm4/api/v1"
	"tFilm4/internal/model"
	"tFilm4/internal/service"
)

type cMovie struct{}

var Movie = cMovie{}

func (c *cMovie) CreateMovie(ctx context.Context, req *v1.CreateMovieReq) (res *v1.CreateMovieRes, err error) {
	err = service.Movie().CreateMovie(ctx, model.CreateMovieInput{
		MovieName:        req.MovieName,
		MovieDirector:    req.MovieDirector,
		MovieActor:       req.MovieActor,
		MovieImage:       req.MovieImage,
		MovieDescription: req.MovieDescription,
		MovieDuration:    req.MovieDuration,
		MovieShowTime:    req.MovieShowTime,
	})
	return
}

func (c *cMovie) GetMovieList(ctx context.Context, req *v1.GetMovieListReq) (res *v1.GetMovieListRes, err error) {
	count, movies, err := service.Movie().GetMovieList(ctx, model.GetMovieInput{
		PageSize:  req.PageSize,
		PageNum:   req.PageNum,
		SearchKey: req.SearchKey,
	})
	res = &v1.GetMovieListRes{
		Movies:     movies,
		MovieCount: count,
	}
	return
}

func (c *cMovie) UpdateMovie(ctx context.Context, req *v1.UpdateMovieReq) (res *v1.UpdateMovieHallRes, err error) {
	err = service.Movie().UpdateMovie(ctx, *req.Movie)
	return
}

func (c *cMovie) GetMovieById(ctx context.Context, req *v1.GetMovieByIdReq) (res *v1.GetMovieByIdRes, err error) {
	movie, err := service.Movie().GetMovieById(ctx, req.MovieId)
	res = &v1.GetMovieByIdRes{Movie: movie}
	return
}

func (c *cMovie) GetShowingMovieList(ctx context.Context, req *v1.GetShowingMovieListReq) (res *v1.GetShowingMovieListRes, err error) {
	count, movies, err := service.Movie().GetShowingMovieList(ctx)
	res = &v1.GetShowingMovieListRes{
		Movies:     movies,
		MovieCount: count,
	}
	return
}

func (c *cMovie) GetComingMovieList(ctx context.Context, req *v1.GetComingMovieListReq) (res *v1.GetComingMovieListRes, err error) {
	count, movies, err := service.Movie().GetComingMovieList(ctx)
	res = &v1.GetComingMovieListRes{
		Movies:     movies,
		MovieCount: count,
	}
	return
}
